package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.Getter;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "护理计划相关接口")
@RestController
@RequestMapping("/nursing")
public class NursingPlanController {
    @Autowired
    private NursingPlanService nursingPlanService;


    /**
     * 分页查询护理计划
     * @param name 护理计划名称
     * @param status 护理计划状态
     * @param pageNum 当前页码
     * @param pageSize 显示数据条数
     * @return
     */
    @GetMapping("/plan/search")
    @ApiOperation(value = "分页查询护理计划接口")
    public ResponseResult getByPage(
            @ApiParam("护理计划名称") String name,
            @ApiParam("护理计划状态") Integer status,
            @ApiParam("当前页码") @RequestParam(defaultValue = "1") Integer pageNum,
            @ApiParam("显示数据条数") @RequestParam(defaultValue = "10") Integer pageSize
    ){
        PageResponse<NursingPlanVo> pageResponse =  nursingPlanService.getByPage(name,status,pageNum,pageSize);
        return ResponseResult.success(pageResponse);
    }

    /**
     * 添加护理计划
     * @param nursingPlanDto 护理计划内容
     * @return
     */
    @PostMapping("/plan")
    @ApiOperation(value = "添加护理计划接口")
    public ResponseResult addPlan(@RequestBody NursingPlanDto nursingPlanDto){
        nursingPlanService.addPlan(nursingPlanDto);
        return ResponseResult.success();
    }

    /**
     * 删除护理计划
     * @param id 要删除的护理计划id
     * @return
     */
    @ApiOperation(value = "删除护理计划接口")
    @DeleteMapping("/plan/{id}")
    public ResponseResult deletePlan(
            @ApiParam(value = "护理计划id")
            @PathVariable Long id){
        nursingPlanService.delete(id);
        return ResponseResult.success();
    }

    /**
     * 根据id查询护理计划计划
     * @param id 护理计划id
     * @return 护理计划详情
     */
    @ApiOperation(value = "根据id查询护理计划计划接口")
    @GetMapping("/plan/{id}")
    public ResponseResult getById(
            @ApiParam(value = "护理计划id")
            @PathVariable Long id){
        NursingPlanVo nursingPlanVo = nursingPlanService.getById(id);
        return ResponseResult.success(nursingPlanVo);
    }

    /**
     * 编辑护理计划
     * @param nursingPlanDto 护理计划信息
     * @return
     */
    @ApiOperation(value = "编辑护理计划接口")
    @PutMapping("/plan")
    public ResponseResult updatePlan(
            @ApiParam(value = "护理项目id")
            @RequestBody NursingPlanDto nursingPlanDto
    ){
        nursingPlanService.updatePlan(nursingPlanDto);
        return ResponseResult.success();
    }

    /**
     * 改变护理计划状态
     * @param id 护理计划id
     * @param status 状态
     * @return
     */
    @ApiOperation(value = "禁用启用接口")
    @PutMapping("/{id}/status/{status}")
    public ResponseResult updateStatus(
            @ApiParam(value = "护理计划id")
            @PathVariable Long id,
            @ApiParam(value = "状态")
            @PathVariable Integer status
    ){
        nursingPlanService.updateStatus(id,status);
        return ResponseResult.success();
    }

    /**
     * 查询所有护理计划
     * @return
     */
    @ApiOperation(value = "查询所有护理计划接口")
    @GetMapping("/plan")
    public ResponseResult getAllPlan(){
        List<NursingPlanVo> nursingPlanVos = nursingPlanService.getAllPlan();
        return ResponseResult.success(nursingPlanVos);
    }

}
